
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>section3 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="section4.html" />
    
    
    <link rel="prev" href="section2.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    chapter1
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="section1.html">
            
                <a href="section1.html">
            
                    
                    section1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="section2.html">
            
                <a href="section2.html">
            
                    
                    section2
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.3" data-path="section3.html">
            
                <a href="section3.html">
            
                    
                    section3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="section4.html">
            
                <a href="section4.html">
            
                    
                    section4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="section5.html">
            
                <a href="section5.html">
            
                    
                    section5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="section6.html">
            
                <a href="section6.html">
            
                    
                    section6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="section7.html">
            
                <a href="section7.html">
            
                    
                    section7
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter2.html">
            
                <a href="../chapter2.html">
            
                    
                    chapter2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter3.html">
            
                <a href="../chapter3.html">
            
                    
                    chapter3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter4.html">
            
                <a href="../chapter4.html">
            
                    
                    chapter4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter5.html">
            
                <a href="../chapter5.html">
            
                    
                    chapter5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter6.html">
            
                <a href="../chapter6.html">
            
                    
                    chapter6
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter6/section1.html">
            
                <a href="../chapter6/section1.html">
            
                    
                    section1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter7.html">
            
                <a href="../chapter7.html">
            
                    
                    chapter7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter8.html">
            
                <a href="../chapter8.html">
            
                    
                    chapter8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter9.html">
            
                <a href="../chapter9.html">
            
                    
                    chapter9
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter10.html">
            
                <a href="../chapter10.html">
            
                    
                    chapter10
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter11.html">
            
                <a href="../chapter11.html">
            
                    
                    chapter11
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../chapter12.html">
            
                <a href="../chapter12.html">
            
                    
                    chapter12
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../chapter13.html">
            
                <a href="../chapter13.html">
            
                    
                    chapter13
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../chapter14.html">
            
                <a href="../chapter14.html">
            
                    
                    chapter14
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../chapter15.html">
            
                <a href="../chapter15.html">
            
                    
                    chapter15
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.1" data-path="../chapter15/section1.html">
            
                <a href="../chapter15/section1.html">
            
                    
                    section15-1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >section3</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="dockerfile">Dockerfile</h1>
<p>Dockerfile&#x7528;&#x6765;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x81EA;&#x5B9A;&#x4E49;&#x7684;image,&#x5305;&#x542B;&#x4E86;&#x7528;&#x6237;&#x6307;&#x5B9A;&#x7684;&#x8F6F;&#x4EF6;&#x4F9D;&#x8D56;&#x7B49;&#x3002;</p>
<p>&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x5305;&#x542B;Dockerfile,&#x4F7F;&#x7528;&#x547D;&#x4EE4;build&#x6765;&#x521B;&#x5EFA;&#x65B0;&#x7684;image</p>
<p>$ cat Dockerfile</p>
<p>FROM docker/whalesay:latest</p>
<p>RUN apt-get -y update &amp;&amp; apt-get install -y fortunes</p>
<p>CMD /usr/games/fortune -a | cowsay</p>
<p>Dockerfile&#x5173;&#x952E;&#x5B57;</p>
<p>&#x5982;&#x4F55;&#x7F16;&#x5199;&#x4E00;&#x4E2A;Dockerfile,&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<p># CommentINSTRUCTION arguments</p>
<p>FROM</p>
<p>&#x57FA;&#x4E8E;&#x54EA;&#x4E2A;&#x955C;&#x50CF;</p>
<p>RUN</p>
<p>&#x5B89;&#x88C5;&#x8F6F;&#x4EF6;&#x7528;</p>
<p>MAINTAINER</p>
<p>&#x955C;&#x50CF;&#x521B;&#x5EFA;&#x8005;</p>
<p>CMD</p>
<p>Container&#x542F;&#x52A8;&#x65F6;&#x6267;&#x884C;&#x7684;&#x547D;&#x4EE4;&#xFF0C;&#x4F46;&#x662F;&#x4E00;&#x4E2A;Dockerfile&#x4E2D;&#x53EA;&#x80FD;&#x6709;&#x4E00;&#x6761;CMD&#x547D;&#x4EE4;&#xFF0C;&#x591A;&#x6761;&#x5219;&#x53EA;&#x6267;&#x884C;&#x6700;&#x540E;&#x4E00;&#x6761;CMD.</p>
<p>CMD&#x4E3B;&#x8981;&#x7528;&#x4E8E;container&#x65F6;&#x542F;&#x52A8;&#x6307;&#x5B9A;&#x7684;&#x670D;&#x52A1;&#xFF0C;&#x5F53;Docker run command&#x7684;&#x547D;&#x4EE4;&#x5339;&#x914D;&#x5230;CMD command&#x65F6;&#xFF0C;&#x4F1A;&#x66FF;&#x6362;CMD&#x6267;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x3002;&#x5982;:</p>
<p>Dockerfile:</p>
<p>CMD echo hello world</p>
<p>&#x8FD0;&#x884C;&#x4E00;&#x4E0B;&#x8BD5;&#x8BD5;:</p>
<p>edwardsbean@ed-pc:~/software/docker-image/centos-add-test$ docker run centos-cmd</p>
<p>hello world</p>
<p>&#x4E00;&#x65E6;&#x547D;&#x4EE4;&#x5339;&#x914D;&#xFF1A;</p>
<p>edwardsbean@ed-pc:~/software/docker-image/centos-add-test$ docker run centos-cmd echo hello edwardsbean</p>
<p>hello edwardsbean</p>
<p>ENTRYPOINT</p>
<p>container&#x542F;&#x52A8;&#x65F6;&#x6267;&#x884C;&#x7684;&#x547D;&#x4EE4;&#xFF0C;&#x4F46;&#x662F;&#x4E00;&#x4E2A;Dockerfile&#x4E2D;&#x53EA;&#x80FD;&#x6709;&#x4E00;&#x6761;ENTRYPOINT&#x547D;&#x4EE4;&#xFF0C;&#x5982;&#x679C;&#x591A;&#x6761;&#xFF0C;&#x5219;&#x53EA;&#x6267;&#x884C;&#x6700;&#x540E;&#x4E00;&#x6761;</p>
<p>ENTRYPOINT&#x6CA1;&#x6709;CMD&#x7684;&#x53EF;&#x66FF;&#x6362;&#x7279;&#x6027;</p>
<p>USER</p>
<p>&#x4F7F;&#x7528;&#x54EA;&#x4E2A;&#x7528;&#x6237;&#x8DD1;container</p>
<p>&#x5982;&#xFF1A;</p>
<p>ENTRYPOINT [&quot;memcached&quot;]</p>
<p>USER daemon</p>
<p>EXPOSE</p>
<p>container&#x5185;&#x90E8;&#x670D;&#x52A1;&#x5F00;&#x542F;&#x7684;&#x7AEF;&#x53E3;&#x3002;&#x4E3B;&#x673A;&#x4E0A;&#x8981;&#x7528;&#x8FD8;&#x5F97;&#x5728;&#x542F;&#x52A8;container&#x65F6;&#xFF0C;&#x505A;host-container&#x7684;&#x7AEF;&#x53E3;&#x6620;&#x5C04;&#xFF1A;</p>
<p>docker run -d -p 127.0.0.1:33301:22 centos6-ssh</p>
<p>container ssh&#x670D;&#x52A1;&#x7684;22&#x7AEF;&#x53E3;&#x88AB;&#x6620;&#x5C04;&#x5230;&#x4E3B;&#x673A;&#x7684;33301&#x7AEF;&#x53E3;</p>
<p>ENV</p>
<p>&#x7528;&#x6765;&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF0C;&#x6BD4;&#x5982;&#xFF1A;</p>
<p>ENV LANG en_US.UTF-8</p>
<p>ENV LC_ALL en_US.UTF-8</p>
<p>ADD</p>
<p>&#x5C06;&#x6587;&#x4EF6;&lt;src&gt;&#x62F7;&#x8D1D;&#x5230;container&#x7684;&#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#x5BF9;&#x5E94;&#x7684;&#x8DEF;&#x5F84;&lt;dest&gt;</p>
<p>&#x6240;&#x6709;&#x62F7;&#x8D1D;&#x5230;container&#x4E2D;&#x7684;&#x6587;&#x4EF6;&#x548C;&#x6587;&#x4EF6;&#x5939;&#x6743;&#x9650;&#x4E3A;0755,uid&#x548C;gid&#x4E3A;0</p>
<p>&#x5982;&#x679C;&#x6587;&#x4EF6;&#x662F;&#x53EF;&#x8BC6;&#x522B;&#x7684;&#x538B;&#x7F29;&#x683C;&#x5F0F;&#xFF0C;&#x5219;docker&#x4F1A;&#x5E2E;&#x5FD9;&#x89E3;&#x538B;&#x7F29;</p>
<p>&#x5982;&#x679C;&#x8981;ADD&#x672C;&#x5730;&#x6587;&#x4EF6;&#xFF0C;&#x5219;&#x672C;&#x5730;&#x6587;&#x4EF6;&#x5FC5;&#x987B;&#x5728; docker build &lt;PATH&gt;&#xFF0C;&#x6307;&#x5B9A;&#x7684;&lt;PATH&gt;&#x76EE;&#x5F55;&#x4E0B;</p>
<p>&#x5982;&#x679C;&#x8981;ADD&#x8FDC;&#x7A0B;&#x6587;&#x4EF6;&#xFF0C;&#x5219;&#x8FDC;&#x7A0B;&#x6587;&#x4EF6;&#x5FC5;&#x987B;&#x5728; docker build &lt;PATH&gt;&#xFF0C;&#x6307;&#x5B9A;&#x7684;&lt;PATH&gt;&#x76EE;&#x5F55;&#x4E0B;&#x3002;&#x6BD4;&#x5982;:</p>
<p>docker build github.com/creack/docker-firefox</p>
<p>docker-firefox&#x76EE;&#x5F55;&#x4E0B;&#x5FC5;&#x987B;&#x6709;Dockerfile&#x548C;&#x8981;ADD&#x7684;&#x6587;&#x4EF6;</p>
<p>&#x6CE8;&#x610F;:&#x4F7F;&#x7528;docker build - &lt; somefile&#x65B9;&#x5F0F;&#x8FDB;&#x884C;build&#xFF0C;&#x662F;&#x4E0D;&#x80FD;&#x76F4;&#x63A5;&#x5C06;&#x672C;&#x5730;&#x6587;&#x4EF6;ADD&#x5230;container&#x4E2D;&#x3002;&#x53EA;&#x80FD;ADD</p>
<p>url file.</p>
<p>ADD&#x53EA;&#x6709;&#x5728;build&#x955C;&#x50CF;&#x7684;&#x65F6;&#x5019;&#x8FD0;&#x884C;&#x4E00;&#x6B21;&#xFF0C;&#x540E;&#x9762;&#x8FD0;&#x884C;container&#x7684;&#x65F6;&#x5019;&#x4E0D;&#x4F1A;&#x518D;&#x91CD;&#x65B0;&#x52A0;&#x8F7D;&#x4E86;&#x3002;</p>
<p>VOLUME</p>
<p>&#x53EF;&#x4EE5;&#x5C06;&#x672C;&#x5730;&#x6587;&#x4EF6;&#x5939;&#x6216;&#x8005;&#x5176;&#x4ED6;container&#x7684;&#x6587;&#x4EF6;&#x5939;&#x6302;&#x8F7D;&#x5230;container&#x4E2D;&#x3002;</p>
<p>WORKDIR</p>
<p>&#x5207;&#x6362;&#x76EE;&#x5F55;&#x7528;&#xFF0C;&#x53EF;&#x4EE5;&#x591A;&#x6B21;&#x5207;&#x6362;(&#x76F8;&#x5F53;&#x4E8E;cd&#x547D;&#x4EE4;)&#xFF0C;&#x5BF9;RUN,CMD,ENTRYPOINT&#x751F;&#x6548;</p>
<p>ONBUILD</p>
<p>ONBUILD &#x6307;&#x5B9A;&#x7684;&#x547D;&#x4EE4;&#x5728;&#x6784;&#x5EFA;&#x955C;&#x50CF;&#x65F6;&#x5E76;&#x4E0D;&#x6267;&#x884C;&#xFF0C;&#x800C;&#x662F;&#x5728;&#x5B83;&#x7684;&#x5B50;&#x955C;&#x50CF;&#x4E2D;&#x6267;&#x884C;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="section2.html" class="navigation navigation-prev " aria-label="Previous page: section2">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="section4.html" class="navigation navigation-next " aria-label="Next page: section4">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"section3","level":"1.2.3","depth":2,"next":{"title":"section4","level":"1.2.4","depth":2,"path":"chapter1/section4.md","ref":"chapter1/section4.md","articles":[]},"previous":{"title":"section2","level":"1.2.2","depth":2,"path":"chapter1/section2.md","ref":"chapter1/section2.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter1/section3.md","mtime":"2017-04-28T12:04:35.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-28T12:19:03.600Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

